<?php

namespace backend\modules\trancfg\models;

use Yii;
use yii\base\Model;
use yii\data\ActiveDataProvider;
use backend\modules\trancfg\models\Pubtrandict;

/**
 * PubtrandictSearch represents the model behind the search form about `backend\modules\trancfg\models\Pubtrandict`.
 */
class PubtrandictSearch extends Pubtrandict
{
    public function rules()
    {
        return [
            [['MTID', 'ROUTEID', 'IOFLAG', 'DICTCODE', 'DICTTYPE', 'DICTNAME', 'FLAG', 'SUBMARK', 'SUBCOND', 'FIELD', 'PATH', 'DEFVAL', 'DEALFUNC', 'MEMO'], 'safe'],
            [['SEQNO', 'DICTLEN', 'DECLEN'], 'integer'],
        ];
    }

    public function scenarios()
    {
        // bypass scenarios() implementation in the parent class
        return Model::scenarios();
    }

    public function search($params)
    {
        $query = Pubtrandict::find();

        $dataProvider = new ActiveDataProvider([
            'query' => $query,
        ]);

        if (!($this->load($params) && $this->validate())) {
            return $dataProvider;
        }

        $query->andFilterWhere([
            'SEQNO' => $this->SEQNO,
            'DICTLEN' => $this->DICTLEN,
            'DECLEN' => $this->DECLEN,
        ]);

        $query->andFilterWhere(['like', 'MTID', $this->MTID])
            ->andFilterWhere(['like', 'ROUTEID', $this->ROUTEID])
            ->andFilterWhere(['like', 'IOFLAG', $this->IOFLAG])
            ->andFilterWhere(['like', 'DICTCODE', $this->DICTCODE])
            ->andFilterWhere(['like', 'DICTTYPE', $this->DICTTYPE])
            ->andFilterWhere(['like', 'DICTNAME', $this->DICTNAME])
            ->andFilterWhere(['like', 'FLAG', $this->FLAG])
            ->andFilterWhere(['like', 'SUBMARK', $this->SUBMARK])
            ->andFilterWhere(['like', 'SUBCOND', $this->SUBCOND])
            ->andFilterWhere(['like', 'FIELD', $this->FIELD])
            ->andFilterWhere(['like', 'PATH', $this->PATH])
            ->andFilterWhere(['like', 'DEFVAL', $this->DEFVAL])
            ->andFilterWhere(['like', 'DEALFUNC', $this->DEALFUNC])
            ->andFilterWhere(['like', 'MEMO', $this->MEMO]);

        return $dataProvider;
    }
}
